import QtQuick 2.11
//import QtQuick.Controls 1.4
import QtQuick.Controls 2.2

import ".."
import "../_Global"
import "../_Global/Button"

import "../_Global/Global.js" as GlobalJS
import "../GameJS.js" as GameJS

Item {
    property int nGroupID: 0

    signal s_GameReady(int duiWu)
    signal s_StartGame()
    signal s_ExitGroup()
    signal showConfig()

    function appendText(msg) {
        msgBox.appendText(msg);
    }
    function clearMsg() {
        msgBox.textArea.text = "";
    }

    id: root
    anchors.fill: parent

    Rectangle {
        id: background
        anchors.fill: parent

        MouseArea { //防穿透
            anchors.fill: parent
        }

        Image { //背景
            id: backImage
            source: Global._FixResourcePath_R("Media/Images/Grades/Back.png")
            anchors.fill: parent
        }

        ImageButton2 {  //设置
            x: Global.dpW(1820)
            y: Global.dpH(0)
            width: Global.dpW(100)
            height: Global.dpH(100)
            source: Global._FixResourcePath_R("Media/Images/Exit/Config.png")
            soundEffectClick: Global.resource.effects.effectButton
            bEffectOn: Global.config.bEffectOn
            onButtonClicked: {
                showConfig();
            }
        }

        ImageButton2 {
            id: buttonReturn
            x: Global.dpW(875)
            y: Global.dpH(915)
            width: Global.dpW(156)
            height: Global.dpH(122)
            source: Global._FixResourcePath_R("Media/Images/Return.png")
            soundEffectClick: Global.resource.effects.effectButton
            bEffectOn: Global.config.bEffectOn

            onButtonClicked: {
                s_ExitGroup();
            }
        }


        //房间号
        Text {
            id: groupIDText
            z: 0.2
            text: "房间号:" + nGroupID
            font {
                //family: Global.resource.fonts.font1.name
                pixelSize: Global.dpH(18)
            }
            style: Text.Outline
            styleColor: "white"
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
            //horizontalAlignment: Text.AlignHCenter
            //verticalAlignment: Text.AlignVCenter
        }
        /*
        ColorButton {
            id: buttonExit
            x: Global.dpW(610)
            y: Global.dpH(110)
            width: Global.dpW(300)
            height: Global.dpH(100)

            Text {
                font.pixelSize: Global.dpH(24)
                text: qsTr("退出房间")
                anchors.fill: parent
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }
            onButtonClicked: {
                s_ExitGroup();
            }
        }
        */

        ColorButton {
            id: buttonReady
            x: Global.dpW(310)
            y: Global.dpH(260)
            width: Global.dpW(300)
            height: Global.dpH(100)
            Text {
                font.pixelSize: Global.dpH(24)
                text: {/*
                    switch(UserInfo.gameStatus) {
                    case 1:
                        return qsTr("取消准备");
                    case 2:
                        return qsTr("准备");
                    case 0:
                        return qsTr("?");
                    case 3:
                        return qsTr("??");
                    default:
                        return qsTr("???");
                    }*/
                    if(UserInfo.gameStatus == 0)
                        return qsTr("?");
                    else if(UserInfo.gameStatus == 1)
                        return qsTr("准备");
                    else if(UserInfo.gameStatus == 2)
                        return qsTr("取消准备");
                    else if(UserInfo.gameStatus == 3)
                        return qsTr("??");
                    else
                        return qsTr("???");
                }
                anchors.fill: parent
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }
            onButtonClicked: {
                if(!isNaN(textDuiWu.text) && textDuiWu.text >= 0)
                    s_GameReady(textDuiWu.text);
                else
                    s_GameReady(GlobalJS.random(0, 9));
            }
        }

        ColorButton {
            id: buttonStart
            x: Global.dpW(610)
            y: Global.dpH(260)
            width: Global.dpW(300)
            height: Global.dpH(100)
            Text {
                font.pixelSize: Global.dpH(24)
                text: qsTr("开始")
                anchors.fill: parent
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }
            onButtonClicked: {
                s_StartGame();
            }
        }

        TextField {
            id: textDuiWu
            x: Global.dpW(910)
            y: Global.dpH(260)
            width: Global.dpW(300)
            height: Global.dpH(100)
            text: "-1"
            enabled: {
                if(UserInfo.gameStatus == 2)
                    return false;
                return true;
            }
            placeholderText: "队伍"
        }

        MsgBox {
            id: msgBox
            x: Global.gamePos.mapInGroup.rectMsgBox.x
            y: Global.gamePos.mapInGroup.rectMsgBox.y
            width: Global.gamePos.mapInGroup.rectMsgBox.width
            height: Global.gamePos.mapInGroup.rectMsgBox.height
            textArea.font.pixelSize: Global.dpH(20)
            textArea.readOnly: true
            textArea.enabled: false
            z: 0.1

            /*anchors {
                top: parent.top
                right: parent.right
                rightMargin: 0
            }*/
            //enabled: false
            //textArea.verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff
            //textArea.horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff

            Component.onCompleted: {
            }
        }

    }

    Component.onCompleted: {
    }

}
